package com.cr.crandroid.adapter;

import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.cr.crandroid.R;
import com.cr.crandroid.bean.Car;

import java.util.List;

public class CarAdapter extends BaseQuickAdapter<Car, BaseViewHolder> {

    public CarAdapter(@Nullable List<Car> data) {
        super(R.layout.item_car, data);
    }

    // 将Car对象的数据绑定到视图上
    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, Car car) {
        baseViewHolder.setText(R.id.textView, car.getBrand());
        baseViewHolder.setText(R.id.textView2, car.getColor());
        baseViewHolder.setText(R.id.textView3, car.getSeatingCapacity());

        if (car.getImage() != null)
            Glide.with(getContext()).load(car.getImage().split(",")[0])
                    .into((ImageView) baseViewHolder.getView(R.id.imageView));
    }
}
